package cn.ym.aircraft;

import javax.swing.*;
import java.awt.image.BufferedImage;
import java.util.Random;

public class Bee extends FlyingObject implements AwardType,EnemyLife,EnemyFire{
    int xSpeed;
    int ySpeed;
    int awardType;

    Bee() {
        super(60, 51);
        this.xSpeed = 9;
        this.ySpeed = 3;
        Random rand = new Random();
        this.awardType = rand.nextInt(2);
    }

    public void step() {
        this.y += this.ySpeed;
        Random rand = new Random();
        int stepType = rand.nextInt(5);
        if (stepType == 0) {
            this.x -= this.xSpeed;
        } else {
            this.x += this.xSpeed;
        }
        if (this.x <= 0 || this.x >= World.WIDTH - this.width) {
            this.xSpeed *= -1;
        }

    }

    private int index = 1;

    @Override
    public BufferedImage getImage() {
        if (isLive()) {
            return Images.bees[0];
        } else if (isDead()) {
            BufferedImage img = Images.bees[index++];
            if (index == Images.bees.length) {
                state = REMOVE;
            }
            return img;
        }
        return null;
    }

    @Override
    public int getAwardType() {
        return awardType;
    }

    @Override
    public int getLife() {
        return 10;
    }

    @Override
    public int getFire() {
        Random rand = new Random();
        return rand.nextInt(500);
    }
}
